<template>
  <div class="list">
    <div
      v-for="item of courseList"
      :key="item.chapterId"
      class="item"
      @click="handlePlayer(item)"
    >
      <div class="img_nav">
        <el-image :src="item.chapterCover" fit="cover" class="img"></el-image>
        <div v-if="item.payShow === 1" class="make">
          <div class="tips">此内容需付费后观看</div>
        </div>
        <div v-if="item.isPlay" class="isplay">正在播放</div>
      </div>
      <div
        class="desc"
        :class="item.isPlay ? 'activeDesc' : ''"
        v-text="item.chapterCname"
      ></div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, PropType, ref, watchEffect } from 'vue'
import courseImg from '@/assets/images/course-img.png'
import { IChapter } from 'apis/types/course'

export default defineComponent({
  props: {
    courseList: {
      type: Array as PropType<IChapter[]>,
      required: true,
    },
  },
  emits: ['player'],
  setup(props, { emit }) {
    const handlePlayer = (item: IChapter) => {
      emit('player', item)
    }
    return {
      handlePlayer,
    }
  },
})
</script>

<style scoped lang="scss">
.list {
  margin: 0 56px;
  width: 1200px;
  @include clearfix;
  .item {
    width: 350px;
    float: left;
    margin-left: 16px;
    cursor: pointer;
    &:nth-child(1) {
      margin-left: 0;
    }
    .img_nav {
      width: 100%;
      height: 222px;
      border-radius: 16px;
      overflow: hidden;
      position: relative;
      .img {
        width: 100%;
        height: 222px;
      }
      .make {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.39);
        .tips {
          width: 100%;
          text-align: center;
          font-size: 20px;
          line-height: 250px;
          color: #ffffff;
        }
      }
      .isplay {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        text-align: center;
        font-size: 20px;
        line-height: 222px;
        color: #ffffff;
      }
    }
    .desc {
      font-size: 20px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #333333;
      line-height: 28px;
      height: 56px;
      margin: 20px 8px 4px;
      &.activeDesc {
        text-decoration: underline;
      }
      @include text-ellipsis-multi(2);
    }
  }
}
</style>
